package ru.compscicenter.uno.view.animation;

/**
 * Created by IntelliJ IDEA.
 * User: Павел
 * Date: 31.03.12
 * Time: 10:34
 * To change this template use File | Settings | File Templates.
 */
public class TurnSwitchAnimation {
    private final int x1, y1;
    private final int x2, y2;
    private final long startTime;

    private final int dx, dy, dt;

    public TurnSwitchAnimation(int x1, int y1, int x2, int y2, long startTime, long maxTime) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.startTime = startTime;

        dx = x2 - x1;
        dy = y2 - y1;
        dt = (int) (maxTime - startTime);
    }

    public int getX(int timeAfterStart) {
        if (isFinished(timeAfterStart)) {
            return x2;
        }
        return x1 + dx * timeAfterStart / dt;
    }

    public int getY(int timeAfterStart) {
        if (isFinished(timeAfterStart)) {
            return y2;
        }
        return y1 + dy * timeAfterStart / dt;
    }

    public boolean isFinished(int timeAfterStart) {
        return timeAfterStart >= dt;
    }

    public long getStartTime() {
        return startTime;
    }
}
